#ifndef BSP_PWM_H
#define BSP_PWM_H

#include <stdint.h>
#include "main.h"
#include "stdlib.h"
#include "string.h"

#define PWM_MAX_NUM 12
/**
 * @brief PWM的实例结构体定义
 * 
 */
typedef struct pwm
{
    TIM_HandleTypeDef*  TIMx;       //TIM句柄
    uint32_t            Channel;    //通道
    uint32_t            Period;     //周期
    uint32_t            Duty_Period;      //占空比
    uint32_t            Tclk;        //时钟频率
    void (* pwm_callback)(struct pwm *);
    void* id;
} PWMInstance;

/**
 * @brief PWM的初始化配置结构体定义
 * 
 */
typedef struct 
{
    TIM_HandleTypeDef*  TIMx;
    uint32_t            Channel;
    uint32_t            Period;
    uint32_t            Duty_Period;
    void (* pwm_callback)(PWMInstance* );
    void* id;
} PWM_Init_Config_s;

/**
 * @brief 初始化PWM实例
 * 
 * @param _config 初始化配置
 * @return PWMInstance*
 */
PWMInstance* PWMInit(PWM_Init_Config_s* _config);

/**
 * @brief 启动PWM
 * 
 * @param _instance pwm实例
 * @return void
 */
void PWMStart(PWMInstance* _instance);

/**
 * @brief 停止PWM
 * 
 * @param _instance pwm实例
 * @return void
 */
void PWMStop(PWMInstance* _instance);

/**
 * @brief 设置PWM占空比
 * 
 * @param _instance pwm实例
 * @param dutyratio 占空比 0~1       
 * @return void
 */
void PWMSetDutyRatio(PWMInstance* _instance, float dutyratio);

/**
 * @brief 设置PWM周期
 * 
 * @param _instance pwm实例
 * @param period    周期
 */
void PWMSetPeriod(PWMInstance* _instance, float period);
#endif 
